package com.tsingsoft.wslogs.handle;

import com.tsingsoft.wslogs.domain.LoggerMessage;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * ========================
 *
 * @author bask
 * @Description: TODO
 * @date : 2021/1/8 16:55
 * Version: 1.0
 * ========================
 */
public class LoggerQueue {

    public static final int QUEUE_MAX_SIZE = 10000;
    private static LoggerQueue alarmMessageQueue = new LoggerQueue();
    private BlockingQueue blockingQueue = new LinkedBlockingQueue(10000);

    private LoggerQueue() {
    }

    public static LoggerQueue getInstance() {
        return alarmMessageQueue;
    }

    public boolean push(LoggerMessage log) {
        return this.blockingQueue.add(log);
    }

    public LoggerMessage poll() {
        LoggerMessage result = null;

        try {
            result = (LoggerMessage)this.blockingQueue.take();
        } catch (InterruptedException var3) {
            var3.printStackTrace();
        }

        return result;
    }
}
